//
//  LYBusinessCardCell.m
//  SelectCity
//
//  Created by liuyan on 2019/3/28.
//  Copyright © 2019年 liuyan. All rights reserved.
//

#import "LYBusinessCardCell.h"

@interface LYBusinessCardCell()

@property (nonatomic, strong) UIButton *leftBtn;
@property (nonatomic, strong) UIButton *rightBtn;

@end

@implementation LYBusinessCardCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}
#pragma mark - InitSubViews
- (void)initUI {
    self.backgroundColor = COLOR_OF_CLEAR;
    self.contentView.backgroundColor = COLOR_OF_CLEAR;
    
    CGFloat height = (WIDTH-40.0*Scale)* 685/1005;
    
    self.cardview = [[LYBusinessCardView alloc] initWithFrame:CGRectMake(20*Scale, 10, WIDTH - 40*Scale, height)];
    self.cardview.backgroundColor = COLOR_OF_WHITE;
    self.cardview.layer.cornerRadius = 5;
    self.cardview.layer.masksToBounds = YES;
    [self.contentView addSubview:self.cardview];
    
    self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.leftBtn.frame = CGRectMake(15, self.cardview.bottom + 10, 80, 30);
    [self.leftBtn setTitle:@" 保存" forState:UIControlStateNormal];
    [self.leftBtn setImage:[UIImage imageNamed:@"baocun"] forState:UIControlStateNormal];
    [self.leftBtn setTitleColor:THEMECOLOR_OF_TEXT_666666 forState:UIControlStateNormal];
    self.leftBtn.layer.cornerRadius = self.leftBtn.height/2;
    self.leftBtn.clipsToBounds = YES;
    self.leftBtn.layer.borderWidth = 1;
    self.leftBtn.layer.borderColor = THEMECOLOR_OF_TEXT_666666.CGColor;
    self.leftBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.leftBtn addTarget:self action:@selector(leftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.leftBtn];
    
    self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.rightBtn.frame = CGRectMake(WIDTH - 95, self.cardview.bottom + 10, 80, 30);
    [self.rightBtn setTitleColor:THEMECOLOR_OF_TEXT_666666 forState:UIControlStateNormal];
    self.rightBtn.layer.cornerRadius = self.leftBtn.height/2;
    self.rightBtn.clipsToBounds = YES;
    self.rightBtn.layer.borderWidth = 1;
    self.rightBtn.layer.borderColor = THEMECOLOR_OF_TEXT_666666.CGColor;
    self.rightBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.rightBtn];
//    self.rightBtn.hidden = YES;
}

#pragma mark -- Action
- (void)rightBtnClick:(UIButton *)button {
    _block(1);
}

- (void)leftBtnClick:(UIButton *)button {
    _block(0);
}
- (void)setModel:(MineBusinessCardBaseModel *)model {
    if ([model.type integerValue] == 1) { //企业
        [self.rightBtn setTitle:@" 删除" forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage imageNamed:@"shanchu"] forState:UIControlStateNormal];
    } else { //个人
        [self.rightBtn setTitle:@" 分享" forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage imageNamed:@"share_icon"] forState:UIControlStateNormal];
    }
    _cardview.model = model;
}
- (void)reloadDataForModel:(MineBusinessCardBaseModel *)model indexPath:(nonnull NSIndexPath *)indexPath {
    _rightBtn.indexPath = indexPath;
    if (indexPath.section) { // 删除
        [self.rightBtn setTitle:@" 删除" forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage imageNamed:@"shanchu"] forState:UIControlStateNormal];
    } else { // 分享
        [self.rightBtn setTitle:@" 分享" forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage imageNamed:@"share_icon"] forState:UIControlStateNormal];
    }
    
    _cardview.model = model;
}
    
/*
- (void)setModel:(MineBusinessCardModel *)model {
    if (model.type == 1) {
        //企业
        [self.rightBtn setTitle:@" 删除" forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage imageNamed:@"shanchu"] forState:UIControlStateNormal];
    }else{
        //个人
        [self.rightBtn setTitle:@" 分享" forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage imageNamed:@"share_icon"] forState:UIControlStateNormal];
    }
    _cardview.model = model;
    _cardview.layer.cornerRadius = 5;
    _cardview.clipsToBounds = YES;
}
*/
/*
-(void)setModel:(LYBusinessCardModel *)model{
    if (model.type == 1) {
        //企业
        [self.rightBtn setTitle:@" 删除" forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage imageNamed:@"shanchu"] forState:UIControlStateNormal];
    }else{
        //个人
        [self.rightBtn setTitle:@" 分享" forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage imageNamed:@"share_icon"] forState:UIControlStateNormal];
    }
    _cardview.model = model;
    _cardview.layer.cornerRadius = 5;
    _cardview.clipsToBounds = YES;
}
*/

@end
